package com.it.sun.yuebike.common.controller;

import cn.hutool.core.util.StrUtil;
import com.it.sun.yuebike.framework.model.dto.Result;
import com.it.sun.yuebike.framework.util.MinioUtils;
import com.it.sun.yuebike.framework.util.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName com.it.sun.yuebike.common.controller.FileController
 * @Author sunmannian
 * @Date 2021/6/2 16:08
 * @Version V1.0
 * Description  <通用文件服务>
 * Copyright (C) 北京中电兴发科技有限公司  since 2021/6/2
 */
@Api(tags = "通用——文件服务")
@RestController
@RequestMapping("/oss")
@Slf4j
public class FileController {

    @PostMapping()
    @ApiOperation("上传文件")
    public Result<String> upload(MultipartFile file) {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        String upload = MinioUtils.upload(file, "yue-bike");
        stopWatch.stop();
        log.info("cost time {} s", stopWatch.getTotalTimeSeconds());
        return StrUtil.isBlank(upload) ? ResultUtils.error("文件上传失败!") : ResultUtils.success(upload);

    }

}



